﻿using Dapper;
using OMG.Fill.Mulberry.Model;
using OMG.Fill.Mulberry.Model.Ent;
using ProjectShare;
using System;
using System.Collections.Generic;
using System.Linq;
namespace OMG.Fill.Mulberry.Service
{
    /// <summary>
    /// 填报基本信息T_Report通用操作类
    /// </summary>
    public class ReportServices : Reports
    {
        public Pager<List<ReportModel>> GetPageList(ReportQuery query)
        {
            AreaServices areaService = new AreaServices();
            DictServices dict = new DictServices();
            query.FillInYear = dict.GetKey(query.FillInYear);
            Pager<List<ReportModel>> obj = new Pager<List<ReportModel>>();
            var paramlist = new DynamicParameters();
            string strWhereSql = "";//from 表在下面，需完善其他查询条件在这里接的写，格式为："and xxx=@xxx空格,如下注释部分代码所示："
            if (!string.IsNullOrEmpty(query.FillInYear))
            {
                strWhereSql += "and FillInYear = @FillInYear ";
                paramlist.Add("FillInYear", query.FillInYear);
            }
            if (!string.IsNullOrEmpty(query.TimesType))
            {
                strWhereSql += "and TimesType = @TimesType ";
                paramlist.Add("TimesType", query.TimesType);
            }
            //前端默认设置
            if (!string.IsNullOrEmpty(query.ReportCode))
            {
                strWhereSql += "and ReportCode = @ReportCode ";
                paramlist.Add("ReportCode", query.ReportCode);
            }
            //前端默认设置
            if (!string.IsNullOrEmpty(query.AreaCode))
            {
                strWhereSql += "and AreaCode = @AreaCode ";
                paramlist.Add("AreaCode", query.AreaCode);
            }
            string strFromSql = "from dbo.T_Report where 1=1 " + strWhereSql;
            string strTotal = "select count(1)" + strFromSql + strWhereSql;
            string strOrderSql = " order by FillInYear ";//自定义完成order by语句
            string strSql = @"select * from (select *,ROW_NUMBER() over (order by Id ) as RowNumber " + strFromSql + ") as t ";
            strSql += "where t.RowNumber between  @minRow and @maxRow" + strOrderSql;
            paramlist.Add("minRow", query.MinRow);
            paramlist.Add("maxRow", query.MaxRow);
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    obj.rows = dbCon.Query<ReportModel>(strSql, paramlist).ToList();
                    foreach (var item in obj.rows)
                    {
                        item.StatusName = string.IsNullOrEmpty(item.Status) ? "" : DataDict.Instance["ReportStatus"][item.Status];
                        item.FillInYearName = string.IsNullOrEmpty(item.FillInYear) ? "" : DataDict.Instance["ReportYear"][item.FillInYear];
                        item.ReportCodeName = string.IsNullOrEmpty(item.ReportCode) ? "" : DataDict.Instance["ReportTableName"][item.ReportCode];
                        item.TimesTypeName = string.IsNullOrEmpty(item.TimesType) ? "" : DataDict.Instance["ReportCycle"][item.TimesType];
                        item.AreaCodeName = string.IsNullOrEmpty(item.AreaCode) ? "" : areaService.GetByCodeModel(item.AreaCode).model.Name;
                        item.StrAddTime = item.AddTime == null ? "" : item.AddTime.Value.ToString();
                        item.StrUpdateTime = item.UpdateTime == null ? "" : item.UpdateTime.Value.ToString();
                    }
                    obj.total = dbCon.Query<int>(strTotal, paramlist).FirstOrDefault();
                    obj.status = DefaultKey.SuccessResult;
                    obj.message = "获取成功！";
                    dbCon.Dispose();//数据库连接释放
                    return obj;
                }
            }
            catch (Exception ex)
            {
                obj.status = DefaultKey.ErrorResult;
                obj.message = ex.ToString().Trim();
                LogHelper.ErrorLog("获取填报基本信息T_Report分页列表失败", ex);
                return obj;
            }
        }

        /// <summary>
        /// 审核列表界面
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public Pager<List<ReportModel>> GetReviewPageList(ReportQuery query)
        {
            AreaServices areaService = new AreaServices();
            Pager<List<ReportModel>> obj = new Pager<List<ReportModel>>();
            var paramlist = new DynamicParameters();
            //string strWhereSql = " and Status >'2' ";//from 表在下面，需完善其他查询条件在这里接的写，格式为："and xxx=@xxx空格,如下注释部分代码所示："
            string strWhereSql = "";
            if (!string.IsNullOrEmpty(query.FillInYear))
            {
                strWhereSql += "and FillInYear = @FillInYear ";
                paramlist.Add("FillInYear", query.FillInYear);
            }
            if (!string.IsNullOrEmpty(query.TimesType))
            {
                strWhereSql += "and TimesType = @TimesType ";
                paramlist.Add("TimesType", query.TimesType);
            }
            //报表状态
            if (!string.IsNullOrEmpty(query.Status))
            {
                strWhereSql += "and Status = @Status ";
                paramlist.Add("Status", query.Status);
            }
            //季度选择
            if (!string.IsNullOrEmpty(query.TimesCycle))
            {
                //if (query.TimesCycle == "1") {
                //    query.TimesCycle = "春季";
                //} else if (query.TimesCycle == "2") {
                //    query.TimesCycle = "夏季";
                //} else if (query.TimesCycle == "3") {
                //    query.TimesCycle = "秋季";
                //}
                query.TimesCycle = "1";
                strWhereSql += "and TimesCycle = @TimesCycle ";
                paramlist.Add("TimesCycle", query.TimesCycle);
            }
            //前端默认设置
            if (!string.IsNullOrEmpty(query.ReportCode))
            {
                strWhereSql += "and ReportCode = @ReportCode ";
                paramlist.Add("ReportCode", query.ReportCode);
            }
            //前端默认设置
            if (!string.IsNullOrEmpty(query.AreaCode))
            {

                if (query.AreaCode.Substring(2, 10).Equals("0000000000"))//省级账号
                {
                    strWhereSql += "and AreaCode like @AreaCode ";
                    paramlist.Add("AreaCode", "%" + query.AreaCode.Substring(0, 2) + "%");
                }
                else if (query.AreaCode.Substring(4, 8).Equals("00000000"))//州级账号
                {
                    strWhereSql += "and AreaCode like @AreaCode ";
                    paramlist.Add("AreaCode", "%" + query.AreaCode.Substring(0, 4) + "%");
                }
                else
                {
                    strWhereSql += "and AreaCode = @AreaCode ";
                    paramlist.Add("AreaCode", query.AreaCode);
                }
            }
            string strFromSql = "from dbo.T_Report where 1=1 " + strWhereSql;
            string strTotal = "select count(1)" + strFromSql + strWhereSql;
            string strOrderSql = "AreaCode asc,ReportName asc,TimesCycle asc, ";//自定义完成order by语句
            string strSql = @"select * from (select *,ROW_NUMBER() over (order by " + strOrderSql + " Id asc) as RowNumber " + strFromSql + ") as t ";
            strSql += "where t.RowNumber between  @minRow and @maxRow ";
            paramlist.Add("minRow", query.MinRow);
            paramlist.Add("maxRow", query.MaxRow);
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    obj.rows = dbCon.Query<ReportModel>(strSql, paramlist).ToList();
                    foreach (var item in obj.rows)
                    {
                        
                        item.StatusName = string.IsNullOrEmpty(item.Status) ? "" : DataDict.Instance["ReportStatus"][item.Status];
                        item.FillInYearName = string.IsNullOrEmpty(item.FillInYear) ? "" : DataDict.Instance["ReportYear"][item.FillInYear];
                        item.ReportCodeName = string.IsNullOrEmpty(item.ReportCode) ? "" : DataDict.Instance["ReportTableName"][item.ReportCode];
                        item.TimesTypeName = string.IsNullOrEmpty(item.TimesType) ? "" : DataDict.Instance["ReportCycle"][item.TimesType];
                        item.AreaCodeName = string.IsNullOrEmpty(item.AreaCode) ? "" : areaService.GetByCodeModel(item.AreaCode).model.Name;
                        item.StrAddTime = item.AddTime == null ? "" : item.AddTime.Value.ToString();
                        item.StrUpdateTime = item.UpdateTime == null ? "" : item.UpdateTime.Value.ToString();
                        item.ReportName = item.AreaCodeName + item.ReportName;
                    }
                    obj.total = dbCon.Query<int>(strTotal, paramlist).FirstOrDefault();
                    obj.status = DefaultKey.SuccessResult;
                    obj.message = "获取成功！";
                    dbCon.Dispose();//数据库连接释放
                    return obj;
                }
            }
            catch (Exception ex)
            {
                obj.status = DefaultKey.ErrorResult;
                obj.message = ex.ToString().Trim();
                LogHelper.ErrorLog("获取填报基本信息T_Report分页列表失败", ex);
                return obj;
            }
        }

        public ReportDataModel GetReportData(string reportId, string reportCode)
        {
            ReportDataModel model = new ReportDataModel();
            model.ReportId = reportId;
            model.Opinion = GetModel(reportId).model.Opinion;
            switch (reportCode)
            {
                //桑园面积统计表
                case "MulAreaStatist":
                    MulAreaStatistServices mulAreaStatistServices = new MulAreaStatistServices();
                    model.list = mulAreaStatistServices.GetModel(reportId);
                    break;
                //表2季度生产情况表
                case "MulQuartProduc":
                    MulQuartProducServices mulQuartProducServices = new MulQuartProducServices();
                    model.list = mulQuartProducServices.GetModel(reportId);
                    break;
                //表3全年蚕桑生产情况统计表
                case "MulAnnualProducStatist":
                    MulAnnualProducStatistServices mulAnnualProducStatistServices = new MulAnnualProducStatistServices();
                    model.list = mulAnnualProducStatistServices.GetModel(reportId);
                    break;
                //表4全年饲养蚕品种构成调查表
                case "MulAnnualRear":
                    MulAnnualRearServices mulAnnualRearServices = new MulAnnualRearServices();
                    model.list = mulAnnualRearServices.GetList(reportId);
                    break;
                //表5蚕种生产情况统计表
                case "MulEggsProducStatist":
                    MulEggsProducStatistServices mulEggsProducStatistServices = new MulEggsProducStatistServices();
                    model.list = mulEggsProducStatistServices.GetList(reportId);
                    break;
                //表6蚕桑综合利用情况调查表
                case "MulComplexQuest":
                    MulComplexQuestServices mulComplexQuestServices = new MulComplexQuestServices();
                    model.list = mulComplexQuestServices.GetModel(reportId);
                    break;
                //表7桑园套种农作物情况调查表
                case "MulInterCrops":
                    MulInterCropsServices mulInterCropsServices = new MulInterCropsServices();
                    model.list = mulInterCropsServices.GetInfo(reportId);
                    break;
                //表8养蚕收益调查情况
                case "MulSerEarnSurvey":
                    MulSerEarnSurveyServices mulSerEarnSurveyServices = new MulSerEarnSurveyServices();
                    model.list = mulSerEarnSurveyServices.GetList(reportId);
                    break;
                //表9套种作物收益调查情况
                case "MulCropIncome":
                    MulCropIncomeServices mulCropIncomeServices = new MulCropIncomeServices();
                    model.list = mulCropIncomeServices.GetList(reportId);
                    break;
                //表10县生产信息调查统计表
                case "MulProdInfoChart":
                    MulProdInfoChartServices mulProdInfoChartServices = new MulProdInfoChartServices();
                    model.list = mulProdInfoChartServices.GetModel(reportId);
                    break;
                //表11茧丝绸企业信息调查表
                case "MulSilkCompany":
                    MulSilkCompanyServices mulSilkCompanyServices = new MulSilkCompanyServices();
                    model.list = mulSilkCompanyServices.GetList(reportId);
                    break;
                //表12茧丝绸企业信息调查表
                case "MulSilkwormField":
                    MulSilkwormFieldServices mulSilkwormFieldServices = new MulSilkwormFieldServices();
                    model.list = mulSilkwormFieldServices.GetModel(reportId);
                    break;
                //表12茧丝绸企业信息调查表
                case "CompanyInfo":
                    CompanyInfoServices companyInfoServices = new CompanyInfoServices();
                    model.list = companyInfoServices.GetList(reportId);
                    break;

            }
            return model;

        }
        public ResResult<int> UpStatus(string id, string reportType, string strMsg)
        {
            ResResult<int> obj = new ResResult<int>();
            bool isUp = false;//表1表2是否上报或者审核通过
            bool IsUp1 = false;//表1是否上报或者审核通过
            bool IsUp2 = false;//表2是否上报或者审核通过
            DictServices dictServices = new DictServices(); 
            var Report = GetModel(id).model;//根据ID获取报表实体
            if (Report != null)
            {
                if (Report.ReportCode == "MulAnnualProducStatist" && (reportType == "3" || reportType == "4"))//如果当前上报或者审核的表是表3
                {
                    string FillInYear = dictServices.GetPZName(Report.FillInYear, "ReportYear");
                    #region 表1
                    string Report1Id = GetReportId("MulAreaStatist", Report.AreaCode, Report.FillInYear);
                    ReportQuery model2 = new ReportQuery();
                    model2.FillInYear = FillInYear;
                    model2.AreaCode = Report.AreaCode;
                    model2.ReportCode = "MulQuartProduc";
                    List<ReportModel> list = GetPageList(model2).rows;
                    if (!string.IsNullOrEmpty(Report1Id) && list != null && list.Count == 4)
                    {
                        bool IsUp21 = false; bool IsUp22 = false; bool IsUp23 = false; bool IsUp24 = false;
                        if (reportType == "4")
                        {
                            IsUp1 = GetModel(Report1Id).model.Status == reportType ? true : false;//判断表1是否审核
                            IsUp21 = list[0].Status == reportType ? true : false;
                            IsUp22 = list[1].Status == reportType ? true : false;
                            IsUp23 = list[2].Status == reportType ? true : false;
                            IsUp24 = list[3].Status == reportType ? true : false;
                        }
                        if (reportType == "3")
                        {
                            IsUp1 = GetModel(Report1Id).model.Status == reportType ? true : false || GetModel(Report1Id).model.Status == "4" ? true : false;//判断表1是否或者审核
                            IsUp21 = list[0].Status == reportType ? true : false || list[0].Status == "4" ? true : false;
                            IsUp22 = list[1].Status == reportType ? true : false || list[1].Status == "4" ? true : false;
                            IsUp23 = list[2].Status == reportType ? true : false || list[2].Status == "4" ? true : false;
                            IsUp24 = list[3].Status == reportType ? true : false || list[3].Status == "4" ? true : false;
                        }
                        if (IsUp21 && IsUp22 && IsUp23 && IsUp24)
                        {
                            IsUp2 = true;
                        }
                    }
                    #endregion
                    if (IsUp1 && IsUp2)
                    {
                        isUp = true;
                    }
                }
                else
                {
                    isUp = true;
                }
            }
            if (isUp)
            {
                strMsg = string.IsNullOrEmpty(strMsg) ? "" : strMsg;
                string strSql = @"UPDATE dbo.T_Report set ";
                strSql += "Status = @Status, ";
                strSql += "UpdateTime = @UpdateTime, ";
                strSql += "Opinion = @Opinion ";
                strSql += " where Id = @Id";
                try
                {
                    using (var dbCon = ConnectFactory.GetOpenConnection())
                    {
                        int result = dbCon.Execute(strSql, new { Id = id, Status = reportType, UpdateTime = DateTime.Now, Opinion = strMsg });
                        if (result > 0)
                        {
                            obj.model = result;
                            obj.status = DefaultKey.SuccessResult;
                            obj.message = "更新成功！";
                        }
                        else
                        {
                            obj.model = result;
                            obj.status = DefaultKey.InfoResult;
                            obj.message = "更新失败！数量为:" + result;
                        }
                        dbCon.Dispose();//数据库连接释放
                    }
                }
                catch (Exception ex)
                {
                    obj.status = DefaultKey.ErrorResult;
                    obj.message = ex.ToString().Trim();
                    LogHelper.ErrorLog("更新填报基本信息T_Report对象信息失败", ex);

                }
            }
            else
            {
                obj.status = DefaultKey.ErrorResult;
                if (reportType == "3")
                {
                    if (!IsUp1)
                    {
                        obj.message = "请先完成表1数据的上报或审核";
                    }
                    if (!IsUp2)
                    {
                        obj.message = "请先完成表2四个季度数据的上报或审核";
                    }
                    if (!IsUp1 && !IsUp2)
                    {
                        obj.message = "请先完成表1的上报和表2四个季度数据的上报或审核";
                    }
                }
                if(reportType == "4")
                {
                    if (!IsUp1)
                    {
                        obj.message = "请先完成表1数据的审核";
                    }
                    if (!IsUp2)
                    {
                        obj.message = "请先完成表2四个季度数据的审核";
                    }
                    if (!IsUp1 && !IsUp2)
                    {
                        obj.message = "请先完成表1的上报和表2四个季度数据的审核";
                    }
                }
            }
            return obj;
        }

        public ReportDataModel GetReportData(string reportId, string reportCode,string AreaCode, string FillInYear) {
            ReportDataModel model = new ReportDataModel();
            MulAnnualProducStatistServices mulAnnualProducStatistServices = new MulAnnualProducStatistServices();
            model.ReportId = reportId;
            model.list = mulAnnualProducStatistServices.GetModel(AreaCode, reportId, FillInYear);
            return model;
        }

        public ReportDataModel GetReportData(string reportId, string AreaCode, string FillInYear)
        {
            ReportDataModel model = new ReportDataModel();
            MulAnnualProducStatistServices mulAnnualProducStatistServices = new MulAnnualProducStatistServices();
            model.ReportId = reportId;
            model.list = mulAnnualProducStatistServices.GetDataList(AreaCode, reportId, FillInYear);
            return model;
        }


        public ResResult<List<ReportReview>> GetReportReview(string areaCode,string FillInYear,string Account)
        {
            using (var dbCon = ConnectFactory.GetOpenConnection())
            {
                DictServices dict = new DictServices();
                ResResult<List<ReportReview>> obj = new ResResult<List<ReportReview>>();
                var paramlist = new DynamicParameters();
                string strSql = "select ReportName,ISNULL(a.[0], 0) as 'ReviewFalse' ,";
                strSql += "ISNULL(a.[1], 0) as 'NotFillIn' ,ISNULL(a.[2], 0) as 'FillIn' ,";
                strSql += "ISNULL(a.[3], 0) as 'AlredayReport' ,ISNULL(a.[4], 0) as 'ReviewSuccess' ,";
                strSql += "ISNULL(a.[5], 0) as 'Lock'from(";
                strSql += "select reportName,Status,Sort, COUNT(1) RS from [T_Report]";
                if (!string.IsNullOrEmpty(areaCode) && areaCode != "null")
                {
                    //paramlist.Add("AreaCode", areaCode);
                    //strSql += " where AreaCode = @AreaCode ";
                    if (areaCode.Substring(2, 10).Equals("0000000000"))//省级账号
                    {
                        strSql += "where AreaCode like @AreaCode ";
                        paramlist.Add("AreaCode", "%" + areaCode.Substring(0, 2) + "%");
                    }
                    else if (areaCode.Substring(4, 8).Equals("00000000"))//州级账号
                    {
                        strSql += "where AreaCode like @AreaCode ";
                        paramlist.Add("AreaCode", "%" + areaCode.Substring(0, 4) + "%");
                    }
                    else
                    {
                        strSql += "where AreaCode = @AreaCode ";
                        paramlist.Add("AreaCode", areaCode);
                    }
                }
                if(!string.IsNullOrEmpty(FillInYear))
                {
                    
                    FillInYear = dict.GetKey(FillInYear);
                    strSql += "and FillInYear = @FillInYear ";
                    paramlist.Add("FillInYear", FillInYear);
                }
                strSql += " group by reportName,[Status],Sort";
                strSql += " ) t";
                strSql += " pivot(max(t.RS) FOR t.[Status] IN ([0] , [1], [2], [3], [4], [5])) a   ";
                if (!string.IsNullOrEmpty(Account) && Account != DefaultKey.ProvinceUserAccount)
                {
                    paramlist.Add("sort1", "11");
                    paramlist.Add("sort2", "12");
                    if (Account.Substring(0, 1) == "c")//蚕种场账号
                    {
                        strSql += "where sort = @sort1  or  sort = @sort2  ";
                    }
                    else
                    {
                        strSql += "where sort <> @sort1 and   sort <> @sort2  ";
                    }
                }
                strSql += "  order by Sort asc ";
                try
                {
                    obj.model = dbCon.Query<ReportReview>(strSql, paramlist).ToList();
                    obj.status = DefaultKey.SuccessResult;
                    obj.message = "任务完成结果获取成功";
                }
                catch (Exception ex)
                {
                    obj.status = DefaultKey.ErrorResult;
                    obj.message = "任务完成结果获取失败" + ex.ToString().Trim();
                }
                dbCon.Dispose();//数据库连接释放
                return obj;
            }
        }


        /// <summary>
        /// 获取本年和上一年的数据
        /// </summary>
        /// <param name="nowModel"></param>
        /// <returns></returns>
        public ReportDataModel GetModel(MulNowModel nowModel)
        {
            ReportDataModel model = new ReportDataModel();
            
            switch (nowModel.ReportCode)
            {
                //桑园面积统计表
                case "MulAreaStatist":
                    MulAreaStatistServices mulAreaStatistServices = new MulAreaStatistServices();
                  ResResult<MulAreaStatistViewModel>  AreaRes= mulAreaStatistServices.GetModel(nowModel);
                    model.list = AreaRes;
                    model.ReportId = AreaRes.model.ReportId;
                    model.Opinion = GetModel(model.ReportId).model.Opinion;
                    break;
                //表3全年蚕桑生产情况统计表
                case "MulAnnualProducStatist":
                    MulAnnualProducStatistServices mulAnnualProducStatistServices = new MulAnnualProducStatistServices();
                    ResResult<MulAnnViewModel> MulAnnRes = mulAnnualProducStatistServices.GetModel(nowModel);
                    model.list = MulAnnRes;
                    model.ReportId = MulAnnRes.model.ReportId;
                    model.Opinion = GetModel(model.ReportId).model.Opinion;
                    break;
                //表4全年饲养蚕品种构成调查表
                case "MulAnnualRear":
                    MulAnnualRearServices mulAnnualRearServices = new MulAnnualRearServices();
                    break;
                //表5蚕种生产情况统计表
                case "MulEggsProducStatist":
                    MulEggsProducStatistServices mulEggsProducStatistServices = new MulEggsProducStatistServices();
                    break;
                //表6蚕桑综合利用情况调查表
                case "MulComplexQuest":
                    MulComplexQuestServices mulComplexQuestServices = new MulComplexQuestServices();
                    ResResult<MulComplexViewModel> MulComplexRes = mulComplexQuestServices.GetModel(nowModel);
                    model.list = MulComplexRes;
                    model.ReportId = MulComplexRes.model.ReportId;
                    model.Opinion = GetModel(model.ReportId).model.Opinion;
                    break;
                //表7桑园套种农作物情况调查表
                case "MulInterCrops":
                    MulInterCropsServices mulInterCropsServices = new MulInterCropsServices();
                    break;
                //表8养蚕收益调查情况
                case "MulSerEarnSurvey":
                    MulSerEarnSurveyServices mulSerEarnSurveyServices = new MulSerEarnSurveyServices();
                    break;
                //表9套种作物收益调查情况
                case "MulCropIncome":
                    MulCropIncomeServices mulCropIncomeServices = new MulCropIncomeServices();
                    break;
                //表10县生产信息调查统计表
                case "MulProdInfoChart":
                    MulProdInfoChartServices mulProdInfoChartServices = new MulProdInfoChartServices();
                    ResResult<MulProdViewModel> mulProdInfoChartRes = mulProdInfoChartServices.GetModel(nowModel);
                    model.list = mulProdInfoChartRes;
                    model.ReportId = mulProdInfoChartRes.model.ReportId;
                    model.Opinion = GetModel(model.ReportId).model.Opinion;
                    break;
                //表11桑蚕种场生产经营情况调查表
                case "MulSilkwormField":
                    MulSilkwormFieldServices mulSilkwormFieldServices = new MulSilkwormFieldServices();
                    ResResult<MulSilkwormFieldViewModel> mulSilkwormFieldRes = mulSilkwormFieldServices.GetModel(nowModel);
                    model.list = mulSilkwormFieldRes;
                    model.ReportId = mulSilkwormFieldRes.model.ReportId;
                    model.Opinion = GetModel(model.ReportId).model.Opinion;
                    break;
            }
            return model;
        }

        /// <summary>
        /// 根据地区、报表代码、填报年度判断是否生成过报表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool CheckRepCreate(string ReportCode, string AreaCode, string FillInYear)
        {
            string strSql = @"select count(1) from dbo.T_Report where ReportCode = @ReportCode and AreaCode = @AreaCode and FillInYear = @FillInYear ";
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    //为0，没生成过true,否则false
                    return dbCon.Query<int>(strSql, new { ReportCode = ReportCode, AreaCode = AreaCode, FillInYear = FillInYear }).FirstOrDefault() == 0 ? true : false;
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("当前填报年度的表没有生成过", ex);
                return false;
            }
        }

        /// <summary>
        /// 根据地区、报表代码、填报年度获取报表Id
        /// </summary>
        /// <param name="ReportCode"></param>
        /// <param name="AreaCode"></param>
        /// <param name="FillInYear"></param>
        /// <returns></returns>
        public string GetReportId(string ReportCode, string AreaCode, string FillInYear)
        {
            string strSql = @"select * from dbo.T_Report where ReportCode = @ReportCode and AreaCode = @AreaCode and FillInYear = @FillInYear ";
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    return dbCon.Query<ReportEntity>(strSql, new { ReportCode = ReportCode, AreaCode = AreaCode, FillInYear = FillInYear }).FirstOrDefault().Id;
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("当前填报年度的表没有生成过", ex);
                return "0";
            }
        }
        public ReportEntity GetReportModel(string ReportCode, string AreaCode, string FillInYear) {
            string strSql = @"select * from dbo.T_Report where ReportCode = @ReportCode and AreaCode = @AreaCode and FillInYear = @FillInYear ";
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    return dbCon.Query<ReportEntity>(strSql, new { ReportCode = ReportCode, AreaCode = AreaCode, FillInYear = FillInYear }).FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("当前填报年度的表没有生成过", ex);
                return null;
            }
        }
    }
}